import 'package:bruno/bruno.dart';
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:sph_shipper/AppConfig/Config.dart';
import 'package:sph_shipper/SendGoods/TMSOrlder/ConfirmScheduling.dart';
import 'package:sph_shipper/SendGoods/TMSOrlder/TMSOrderDetial.dart';

import '../../AppConfig/RouteAct.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../http/NoLoadingPostApi.dart';
import '../../http/api.dart';

class AllTMSOrderList extends StatefulWidget {
  const AllTMSOrderList({super.key});

  @override
  State<AllTMSOrderList> createState() => _AllTMSOrderListState();
}

class _AllTMSOrderListState extends State<AllTMSOrderList> {
List dataList=[];
int pageNum=1;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getOrderListAction();
  }
  void getOrderListAction(){
    NoLoadingApiManager.postData(
      context,
      "api/tms/order/page",
      {
        "companyId":"1790927200436183041",
        "current":pageNum,
        "size":20,
      },
          (responseData) async {
          dataList=responseData['data']['records'];
      },
    );
  }


void onReachBottom() {
  setState(() {
    pageNum=pageNum+1;

  });


}



void _onRefresh() {
  setState(() {
    pageNum=1;

  });

  // 在这里可以执行加载更多数据的逻辑
}

@override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return EasyRefresh(
        header:
        ClassicHeader(
          dragText: '下拉刷新',
          armedText: '准备释放',
          readyText: '加载中...',
          processingText: '加载中...',
          processedText: '刷新成功',
          noMoreText: '暂无更多',
          failedText: '刷新失败',
          messageText: '刷新时间 %T',
        ),
        footer: ClassicFooter(
          dragText: '加载更多',
          armedText: '准备释放',
          readyText: '加载中...',
          processingText: '加载中...',
          processedText: '加载成功',
          noMoreText: '暂无更多',
          failedText: '加载失败',
          messageText: '加载时间 %T',
        ),
        onRefresh: _onRefresh,
        onLoad:dataList.length>pageNum*20-1?onReachBottom:null,
        child:
        Container(

        color: Color.fromRGBO(248, 248, 248, 1),
    child:  ListView(

    children: [
      Container(
        margin: EdgeInsets.only(top: 8.h),
          height:screenSize.height-160.h,
          child:
          dataList.isNotEmpty?
          BrnAbnormalStateWidget(
            img: Image.asset(
              'lib/Images/OrderList/找货暂无货源.png',
              scale: 3.0,
            ),
            content: '您的账号暂无订单',
          ): ListView.separated(
            shrinkWrap:true,
            itemCount: 3,
            itemBuilder: (BuildContext context, int index) {
              return GestureDetector(
                onTap: (){
                  Navigator.push( context, FadeRoute(page:TMSOrderDetial(dataMap: dataList[index],)));
                },
                child: Container(
                  margin: EdgeInsets.only(left: 8.w,right: 8.w),
                  padding: EdgeInsets.only(top: 10.h,right: 10.w,bottom: 10.h,left: 10.w),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                        Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Text("YD123456",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Text("苏州速搜物流科技有限公司",style: TextStyle(color: MyColors.textColor,fontSize: 11.sp),),
                          ],
                        ),
                      SizedBox(height: 4.h,),
                      Text("未指定客户",style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),),
                      SizedBox(height: 4.h,),
                      Text("床单丨纸箱丨10吨",style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                      SizedBox(height: 4.h,),
                      Row(
                        children: [
                          Image.asset("lib/Images/OrderList/装icon.png",width: 13.w,height: 13.h,),
                          SizedBox(width: 4.w,),
                          Container(
                            constraints: BoxConstraints(
                              maxWidth:screenSize.width-60.w,

                            ),
                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                          ),

                        ],
                      ),
                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                      Row(
                        children: [
                          Image.asset("lib/Images/OrderList/装icon.png",width: 13.w,height: 13.h,),
                          SizedBox(width: 4.w,),
                          Container(
                            constraints: BoxConstraints(
                              maxWidth:screenSize.width-60.w,

                            ),
                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                          ),

                        ],
                      ),
                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                      Row(
                        children: [
                          Image.asset("lib/Images/OrderList/卸icon.png",width: 13.w,height: 13.h,),
                          SizedBox(width: 4.w,),
                          Container(
                            constraints: BoxConstraints(
                              maxWidth:screenSize.width-60.w,

                            ),
                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                          ),

                        ],
                      ),
                      Image.asset("lib/Images/OrderList/垂直虚线.png",width:13.w ,height:8.h,),
                      Row(
                        children: [
                          Image.asset("lib/Images/OrderList/卸icon.png",width: 13.w,height: 13.h,),
                          SizedBox(width: 4.w,),
                          Container(
                            constraints: BoxConstraints(
                              maxWidth:screenSize.width-60.w,
                            ),
                            child:   Text("江苏省苏州市吴中区展业路",style: TextStyle(color: Colors.black,fontSize: 13.sp),overflow: TextOverflow.ellipsis,),
                          ),

                        ],
                      ),
                      Divider(height: 20.h,color: MyColors.backgreyColor,),

                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [

                          GestureDetector(
                            child:   BrnTagCustom.buildBorderTag(
                              tagText: '调度',
                              textColor:  MyColors.themeColor,
                              borderColor: MyColors.themeColor,
                              borderWidth: 1,
                              fontSize: 13.sp,
                              tagBorderRadius:BorderRadius.all(Radius.circular(30)),
                              textPadding: EdgeInsets.only(left: 10.w,right: 10.w,top: 2.h,bottom: 2.h),
                            ),
                            onTap: (){
                              Navigator.push( context, FadeRoute(page:ConfirmScheduling(
                              )));
                            },
                          ),
                             SizedBox(width: 4.w,),
                             GestureDetector(
                            child:   BrnTagCustom.buildBorderTag(
                              tagText: '修改',
                              textColor:  MyColors.themeColor,
                              borderColor: MyColors.themeColor,
                              borderWidth: 1,
                              fontSize: 13.sp,
                              tagBorderRadius:BorderRadius.all(Radius.circular(30)),
                              textPadding: EdgeInsets.only(left: 10.w,right: 10.w,top: 2.h,bottom: 2.h),
                            ),
                               onTap: (){

                               },
                          ),
                          SizedBox(width: 4.w,),
                          GestureDetector(
                            child:   BrnTagCustom.buildBorderTag(
                              tagText: '再发一单',
                              textColor:  MyColors.themeColor,
                              borderColor: MyColors.themeColor,
                              borderWidth: 1,
                              fontSize: 13.sp,
                              tagBorderRadius:BorderRadius.all(Radius.circular(30)),
                              textPadding: EdgeInsets.only(left: 10.w,right: 10.w,top: 2.h,bottom: 2.h),
                            ),
                            onTap: (){

                            },
                          ),
                          // SizedBox(width: 4.w,),
                          // GestureDetector(
                          //   child:   BrnTagCustom.buildBorderTag(
                          //     tagText: '分享',
                          //     textColor:  MyColors.themeColor,
                          //     borderColor: MyColors.themeColor,
                          //     borderWidth: 1,
                          //     fontSize: 13.sp,
                          //     tagBorderRadius:BorderRadius.all(Radius.circular(30)),
                          //     textPadding: EdgeInsets.only(left: 10.w,right: 10.w,top: 2.h,bottom: 2.h),
                          //   ),
                          // ),
                        ],
                      )
                    ],
                  ),
                ),
              );
            },  separatorBuilder: (context, index) { //自定义分割线
            return   Container(
              height: 8.h,
            );
          },
          )
      )
    ]
    )
        )
    );
  }
}
